********************************************************************************
*Table B3; Column 1 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_less8_blacks, clear


preserve
gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}


reg newbw2500 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state, cluster(mom_birth_state) 
local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore


********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_b3_c1", replace
forvalues i=1/500 {
use $data/estimation_sample_including_less8_blacks, clear


preserve
bsample, cluster(mom_birth_state)


gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_b3_c1, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/


********************************************************************************
*Table B3; Column 2 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_less8_blacks, clear


preserve
gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}


reg newpretermLT37 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state, cluster(mom_birth_state) 
local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore


********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_b3_c2", replace
forvalues i=1/500 {
use $data/estimation_sample_including_less8_blacks, clear


preserve
bsample, cluster(mom_birth_state)


gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_b3_c2, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/

********************************************************************************
*Table B3; Column 3 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_less8_whites, clear


preserve
gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}


reg newbw2500 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state, cluster(mom_birth_state) 
local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore


********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_b3_c3", replace
forvalues i=1/500 {
use $data/estimation_sample_including_less8_whites, clear


preserve
bsample, cluster(mom_birth_state)


gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newbw2500 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_b3_c3, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/


********************************************************************************
*Table B3; Column 4 
********************************************************************************
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/estimation_sample_including_less8_whites, clear


preserve
gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}


reg newpretermLT37 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state, cluster(mom_birth_state) 
local Z=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
lincom (_b[plus0]*meanplus0/`Z')+(_b[plus1]*meanplus1/`Z')+(_b[plus2]*meanplus2/`Z')+(_b[plus3]*meanplus3/`Z')+(_b[plus4]*meanplus4/`Z')

local U=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
lincom (_b[plus0d2]*meanplus0d2/`U')+(_b[plus1d2]*meanplus1d2/`U')+(_b[plus2d2]*meanplus2d2/`U')+(_b[plus3d2]*meanplus3d2/`U')+(_b[plus4d2]*meanplus4d2/`U')
restore


********************************************************************************

set seed 23260513
capture postclose placebo	
postfile placebo c_weighted d_weighted using "$data/table_b3_c4", replace
forvalues i=1/500 {
use $data/estimation_sample_including_less8_whites, clear


preserve
bsample, cluster(mom_birth_state)


gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4

gen plus0d2=plus0*less_8
gen plus1d2=plus1*less_8
gen plus2d2=plus2*less_8
gen plus3d2=plus3*less_8 
gen plus4d2=plus4*less_8 

g bytimesdr= by*less_8
g bstatetimesdr=mom_birth_state*less_8
g agetimesdr=age_cat*less_8
g tbotimesdr =tbo*less_8
g maletimesdr= male*less_8
g yeartimesdr=year*less_8
g bmonthtimesdr=birth_month*less_8

foreach var in Exitexam Perstudentexpenditure Studentteacherratio Povertyrate Unemploymentrate {
gen `var'_int=`var'*less_8
}

global treat_var "plus0 plus0d2 plus1 plus1d2 plus2 plus2d2 plus3 plus3d2 plus4 plus4d2"
global state_var "Exitexam Exitexam_int Perstudentexpenditure Perstudentexpenditure_int Studentteacherratio Studentteacherratio_int Povertyrate Povertyrate_int Unemploymentrate Unemploymentrate_int"
foreach x in $treat_var{
sum `x', meanonly
scalar mean`x'=r(mean)
}

qui reg newpretermLT37 $treat_var less_8 i.age_cat  i.tbo i.male   i.division#c.by i.bytimesdr i.bstatetimesdr i.agetimesdr i.tbotimesdr i.maletimesdr   $state_var i.by i.mom_birth_state
local V=meanplus0+meanplus1+meanplus2+meanplus3+meanplus4
local V_int=meanplus0d2+meanplus1d2+meanplus2d2+meanplus3d2+meanplus4d2
local c_weighted=(_b[plus0]*meanplus0/`V')+(_b[plus1]*meanplus1/`V')+(_b[plus2]*meanplus2/`V')+(_b[plus3]*meanplus3/`V')+(_b[plus4]*meanplus4/`V')
local d_weighted=(_b[plus0d2]*meanplus0d2/`V_int')+(_b[plus1d2]*meanplus1d2/`V_int')+(_b[plus2d2]*meanplus2d2/`V_int')+(_b[plus3d2]*meanplus3d2/`V_int')+(_b[plus4d2]*meanplus4d2/`V_int')
post placebo (`c_weighted') (`d_weighted')
restore
}
postclose placebo



use table_b3_c4, clear

sum  /****Std Dev is the standard error of the weighted point estimate.*/

